package com.osgc.rf.unit.dao;

import java.sql.Connection;
import java.util.ArrayList;
import java.util.List;

import org.apache.log4j.Category;

import com.inca.np.gui.control.DBTableModel;
import com.inca.np.util.SelectHelper;

public class LotInfo {
	static  protected Category logger = Category.getInstance(LotInfo.class);
	public LotInfo() {}
	public LotInfo(String lotid,
	String lotno,
	String validdate) {
		setLotid(lotid);
		setLotno(lotno);
		setValiddate(validdate);
		
	}
	
	static public List<LotInfo> getLotInfos(Connection con,String goodsid)throws Exception {
		List<LotInfo> infos= new ArrayList<LotInfo>();
		LotInfo  info=null;
		String sql = "select * from wms_goods_lot where goodsid="+goodsid;
		logger.debug(sql);
		DBTableModel db = new SelectHelper(sql).executeSelect(con, 0, 1000) ;
		if(db.getRowCount()==0)return null;
		for (int i = 0; i < db.getRowCount(); i++) {
			String lotid = db.getItemValue(i, "lotid");
			String lotno = db.getItemValue(i, "lotno");
			String validdate = db.getItemValue(i, "validdate");
			if(validdate!=null&&validdate.length()>10){
				validdate = validdate.substring(0,10);
			}
			info = new LotInfo(lotid, lotno, validdate);
			infos.add(info);
		}
		return infos;
		
	}
	String lotid;
	String lotno;
	String validdate;
	String proddate;
	String approvedocno;
	String registno;
	String prodlicenseno;
	public String getLotid() {
		return lotid;
	}
	public void setLotid(String lotid) {
		this.lotid = lotid;
	}
	public String getLotno() {
		return lotno;
	}
	public void setLotno(String lotno) {
		this.lotno = lotno;
	}
	public String getValiddate() {
		return validdate;
	}
	public void setValiddate(String validdate) {
		this.validdate = validdate;
	}
	public String getProddate() {
		return proddate;
	}
	public void setProddate(String proddate) {
		this.proddate = proddate;
	}
	public String getApprovedocno() {
		return approvedocno;
	}
	public void setApprovedocno(String approvedocno) {
		this.approvedocno = approvedocno;
	}
	public String getRegistno() {
		return registno;
	}
	public void setRegistno(String registno) {
		this.registno = registno;
	}
	
	static public LotInfo getLotInfo(Connection con,String lotid)throws Exception {

		LotInfo  info=null;
		String sql = "select * from wms_goods_lot where lotid="+lotid;
		logger.debug(sql);
		DBTableModel db = new SelectHelper(sql).executeSelect(con, 0, 1) ;
		if(db.getRowCount()==0)return null;
		for (int i = 0; i < db.getRowCount(); i++) {
			String lotno = db.getItemValue(i, "lotno");
			String validdate = db.getItemValue(i, "validdate");
			info = new LotInfo(lotid, lotno, validdate);
			info.setRegistno(db.getItemValue(i, "registno"));
			info.setProddate(db.getItemValue(i, "proddate"));
			info.setApprovedocno(db.getItemValue(i, "approvedocno"));
			info.setKilllotno(db.getItemValue(i, "killlotno"));
			info.setProdlicenseno(db.getItemValue(i, "prodlicenseno"));
		}
		return info;
		
	}
	private String killlotno;

	public String getKilllotno() {
		return killlotno;
	}
	public void setKilllotno(String killlotno) {
		this.killlotno = killlotno;
	}
	public String getProdlicenseno() {
		return prodlicenseno;
	}
	public void setProdlicenseno(String prodlicenseno) {
		this.prodlicenseno = prodlicenseno;
	}
}
